package com.ethink.order.converter;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import com.ethink.framework.common.converter.Converter;
import com.ethink.order.api.info.TocSaleImportLogInfo;
import com.ethink.order.common.entity.TocSaleImportLog;

import java.time.ZoneId;
import java.util.Date;

/**
 * TOC销售单导入日志 Converter转换器
 *
 * @author default
 * @date 2022-11-22
 */
@Component
public class TocSaleImportLogConverter implements Converter<TocSaleImportLogInfo, TocSaleImportLog> {

    @Override
    public TocSaleImportLog convertTo(TocSaleImportLogInfo info) {
        if(info == null) {
            return null;
        }
        TocSaleImportLog entity = new TocSaleImportLog ();
        BeanUtils.copyProperties(info, entity);
        return entity;
    }

    @Override
    public TocSaleImportLogInfo convertFrom(TocSaleImportLog entity) {
        if(entity == null) {
            return null;
        }
        TocSaleImportLogInfo info = new TocSaleImportLogInfo();
        BeanUtils.copyProperties(entity, info);
        info.setCreateTime(Date.from(entity.getCreateTime().atZone(ZoneId.of("GMT+8")).toInstant()));
        info.setUpdateTime(Date.from(entity.getUpdateTime().atZone(ZoneId.of("GMT+8")).toInstant()));
        return info;
    }
}
